/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pclong.commons;

import com.pclong.model.Stock;
import com.pclong.util.HibernateUtil;
import org.hibernate.Session;

/**
 *
 * @author pcl
 */
public class HibernateExampleApp {

    public static void main(String[] args) {
        System.out.println("Maven + Hibernate + MySQL");
        Session session = HibernateUtil.getSessionFactory().openSession();

        session.beginTransaction();
        Stock stock = new Stock();

        stock.setStockCode("4715");
        stock.setStockName("GENM");

        session.save(stock);
        session.getTransaction().commit();
    }
    /*数据库脚本
    DROP TABLE IF EXISTS `stock`;
    CREATE TABLE `stock` (
    `STOCK_ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `STOCK_CODE` VARCHAR(10) NOT NULL,
    `STOCK_NAME` VARCHAR(20) NOT NULL,
    PRIMARY KEY (`STOCK_ID`) USING BTREE,
    UNIQUE KEY `UNI_STOCK_NAME` (`STOCK_NAME`),
    UNIQUE KEY `UNI_STOCK_ID` (`STOCK_CODE`) USING BTREE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
     */
}
